import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class Query implements Runnable {
    static double totalTime;
    static TestDAO testDAO = new TestDAO();

    @Override
    public void run() {
        while (true) {
            int num = testDAO.sum();
            double startTime = System.nanoTime();
            testDAO.queryPoints(12);
            double endTime = System.nanoTime();
            totalTime = endTime - startTime;
            try {
                String queryTableFileName = "src/query.txt";
                String queryCountFileName = "src/query_count.txt";
                File queryTableFile = new File(queryTableFileName);
                File queryCountFile = new File(queryCountFileName);
                FileWriter fileWriter = new FileWriter(queryTableFile, true);
                FileWriter fileWriter2 = new FileWriter(queryCountFile, true);
                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
                BufferedWriter bufferedWriter2 = new BufferedWriter(fileWriter2);
                bufferedWriter.write(String.valueOf(totalTime / 1000000) + "\n");
                bufferedWriter2.write(String.valueOf(num) + "\n");
                bufferedWriter.close();
                bufferedWriter2.close();
                fileWriter.close();
                fileWriter2.close();
                System.out.println("查询操作" + num + "::" + String.valueOf(totalTime / 1000000) + "ms");
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
